package com.SunSoft.PhoneRemoteControl;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Handler;
import android.os.Message;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.message.BasicNameValuePair;

final class q
  implements Runnable
{
  public final void run()
  {
    label272: int i;
    Object localObject3;
    Object localObject4;
    Object localObject5;
    Object localObject6;
    Object localObject7;
    MainControl.a("Test", "Data_deleing_working start");
    this.a.bo = true;
    String str2 = MainControl.d(this.a).a("save_user");
    String str1 = MainControl.d(this.a).a("save_pass");
    if ((this.a.bj == 19) || (this.a.bj == 24))
    {
      str2 = "tasotest";
      str1 = "4321";
    }
    this.a.bl = 0;
    if ((this.a.bj == 14) || (this.a.bj == 24))
    {
      if (this.a.bj == 24)
      {
        localObject3 = MainControl.f(this.a).rawQuery("select *  from control_list where ID = ? order by come_from desc,ID desc", new String[] { String.valueOf(this.a.T) });
        this.a.bm = ((Cursor)localObject3).getCount();
        if (this.a.bm > 0)
          if (((Cursor)localObject3).moveToNext())
            break label272;
      }
      while (true)
      {
        while (true)
        {
          ((Cursor)localObject3).close();
          localObject1 = new Message();
          ((Message)localObject1).what = this.a.bj;
          this.a.ca.sendMessage((Message)localObject1);
          this.a.bo = false;
          MainControl.a("Test", "Data_deleing_working end");
          return;
          localObject3 = MainControl.i(this.a).rawQuery("select *  from control_list where ID > ?  and come_from<>? order by come_from desc,ID desc", new String[] { "0", "10" });
        }
        MainControl.a("Test", "backup," + String.valueOf(this.a.bl) + ":" + ((Cursor)localObject3).getString(((Cursor)localObject3).getColumnIndex("name_ch")));
        Object localObject1 = str2 + "##";
        localObject7 = "";
        localObject6 = "";
        localObject5 = "";
        localObject4 = "";
        i = ((Cursor)localObject3).getInt(((Cursor)localObject3).getColumnIndex("come_from"));
        if (this.a.bj == 24)
          i = 2;
        String str3 = new StringBuilder(String.valueOf(new StringBuilder(String.valueOf(new StringBuilder(String.valueOf(new StringBuilder(String.valueOf(new StringBuilder(String.valueOf(new StringBuilder(String.valueOf(new StringBuilder(String.valueOf(new StringBuilder(String.valueOf(new StringBuilder(String.valueOf(new StringBuilder(String.valueOf(localObject1)).append(((Cursor)localObject3).getString(((Cursor)localObject3).getColumnIndex("device_ID"))).append("##").toString())).append(MainControl.a(((Cursor)localObject3).getString(((Cursor)localObject3).getColumnIndex("define_ID")))).append("##").toString())).append(MainControl.a(((Cursor)localObject3).getString(((Cursor)localObject3).getColumnIndex("brand_en")))).append("##").toString())).append(MainControl.a(((Cursor)localObject3).getString(((Cursor)localObject3).getColumnIndex("brand_ch")))).append("##").toString())).append(MainControl.a(((Cursor)localObject3).getString(((Cursor)localObject3).getColumnIndex("control_type")))).append("##").toString())).append(MainControl.a(((Cursor)localObject3).getString(((Cursor)localObject3).getColumnIndex("name_en")))).append("##").toString())).append(MainControl.a(((Cursor)localObject3).getString(((Cursor)localObject3).getColumnIndex("name_ch")))).append("##").toString())).append(MainControl.a(((Cursor)localObject3).getString(((Cursor)localObject3).getColumnIndex("control_model")))).append("##").toString())).append(MainControl.a(((Cursor)localObject3).getString(((Cursor)localObject3).getColumnIndex("control_version")))).append("##").toString())).append(String.valueOf(i)).append("##").toString() + MainControl.a(((Cursor)localObject3).getString(((Cursor)localObject3).getColumnIndex("note"))) + "##";
        if (i > 1)
        {
          localObject1 = ((Cursor)localObject3).getString(((Cursor)localObject3).getColumnIndex("define_ID"));
          if (this.a.bj == 24)
          {
            localObject1 = MainControl.f(this.a).rawQuery("select code_str,dis_ch,dis_en,note,order_ID,define_ID  from button_data where define_ID = ? order by order_ID", new String[] { localObject1 });
            if (((Cursor)localObject1).getCount() <= 0)
              break label1491;
            if (((Cursor)localObject1).moveToNext())
              break label1312;
            localObject1 = str3 + ((String)localObject7) + "##" + ((String)localObject6) + "##" + ((String)localObject5) + "##" + ((String)localObject4) + "##";
            localObject1 = localObject1 + MainControl.b(((Cursor)localObject3).getString(((Cursor)localObject3).getColumnIndex("update_time"))) + "##";
            this.a.an = new ArrayList();
            this.a.an.add(new BasicNameValuePair("txtUser_name", str2));
            this.a.an.add(new BasicNameValuePair("txtPassword", str1));
            if ((this.a.bl != 0) || (this.a.bj == 24))
              break label1541;
            this.a.an.add(new BasicNameValuePair("action_value", "del"));
            this.a.an.add(new BasicNameValuePair("control_data_value", (String)localObject1));
            this.a.bb = "http://www.tasogo.com/user_control.aspx";
            this.a.bc = dg.a(this.a.bb, this.a.an);
            if (!(this.a.bc.startsWith("1||1")))
              break label1578;
            localObject1 = this.a;
            ((MainControl)localObject1).bl += 1;
            MainControl.a("Test", "backup," + String.valueOf(this.a.bl) + ":" + this.a.bc);
          }
        }
        try
        {
          while (true)
          {
            while (true)
            {
              while (true)
              {
                while (true)
                {
                  while (true)
                    do
                      Thread.sleep(100L);
                    while (((this.a.bl == 30) && (this.a.bj != 24)) || (this.a.H));
                  localObject1 = MainControl.i(this.a).rawQuery("select code_str,dis_ch,dis_en,note,order_ID,define_ID  from button_data where define_ID = ? order by order_ID", new String[] { localObject1 });
                }
                label1312: localObject7 = localObject7 + MainControl.a(((Cursor)localObject1).getString(((Cursor)localObject1).getColumnIndex("dis_ch"))) + "$$";
                localObject6 = localObject6 + MainControl.a(((Cursor)localObject1).getString(((Cursor)localObject1).getColumnIndex("dis_en"))) + "$$";
                localObject5 = localObject5 + MainControl.a(((Cursor)localObject1).getString(((Cursor)localObject1).getColumnIndex("code_str"))) + "$$";
                localObject4 = localObject4 + MainControl.a(((Cursor)localObject1).getString(((Cursor)localObject1).getColumnIndex("note"))) + "$$";
              }
              label1491: localObject1 = str3 + " ## ## ## ##";
            }
            localObject1 = str3 + " ## ## ## ##";
          }
          label1541: label1578: this.a.an.add(new BasicNameValuePair("action_value", "add"));
        }
        catch (InterruptedException localInterruptedException1)
        {
          while (true)
          {
            while (true)
              localInterruptedException1.printStackTrace();
            MainControl.a("Test", "backup," + String.valueOf(this.a.bl) + ":" + localInterruptedException1);
            MainControl.a("Test", "backup," + String.valueOf(this.a.bl) + ":" + this.a.bc);
          }
        }
      }
    }
    if ((this.a.bk > 0) && (this.a.bn.length > 0))
    {
      this.a.bl = 0;
      i = 0;
      if (i < this.a.bn.length)
        break label1746;
    }
    while (true)
    {
      label1746: int j;
      Object localObject2;
      while (true)
      {
        localObject2 = new Message();
        ((Message)localObject2).what = this.a.bj;
        this.a.ca.sendMessage((Message)localObject2);
      }
      this.a.an = new ArrayList();
      this.a.an.add(new BasicNameValuePair("txtUser_name", str2));
      this.a.an.add(new BasicNameValuePair("txtPassword", str1));
      if (MainControl.d)
      {
        this.a.an.add(new BasicNameValuePair("action_value", "imp"));
        this.a.an.add(new BasicNameValuePair("control_data_value", this.a.bn[i]));
        this.a.bb = "http://www.tasogo.com/user_control.aspx";
        this.a.bc = dg.a(this.a.bb, this.a.an);
        if (!(this.a.bc.startsWith("1||1||")))
          break label2761;
        this.a.bc = this.a.bc.substring(6);
        MainControl.a("Test", "restore," + String.valueOf(this.a.bl) + ":" + this.a.bc);
        localObject3 = this.a.bc.split("##");
        MainControl.a("Test", "get_value_list," + localObject3.length);
        if (localObject3.length >= 15)
        {
          j = Integer.valueOf(localObject3[4]).intValue();
          int k = Integer.valueOf(localObject3[9]).intValue();
          localObject4 = localObject3[0];
          localObject2 = localObject3[1];
          if (!(MainControl.d))
            break label2557;
          MainControl.f(this.a).execSQL("delete from control_list where device_ID= ?", new String[] { localObject4 });
          MainControl.f(this.a).execSQL("delete from button_data where define_ID=? ", new String[] { localObject2 });
          localObject5 = new Object[13];
          localObject5[1] = localObject2;
          localObject5[2] = Integer.valueOf(j);
          localObject5[3] = MainControl.b(localObject3[5]);
          localObject5[4] = MainControl.b(localObject3[3]);
          localObject5[5] = MainControl.b(localObject3[7]);
          localObject5[6] = MainControl.b(localObject3[8]);
          localObject5[7] = Integer.valueOf(k);
          localObject5[8] = localObject4;
          localObject5[9] = MainControl.b(localObject3[10]);
          localObject5[11] = MainControl.b(localObject3[2]);
          localObject5[12] = MainControl.b(localObject3[6]);
          if (!(MainControl.d))
            break label2604;
          localObject5[7] = Integer.valueOf(1);
          MainControl.f(this.a).execSQL("insert into control_list (ID,define_ID,control_type,name_ch,brand_ch,control_model,control_version,come_from,device_ID,note,update_time,brand_en,name_en) values (?,?,?,?,?,?,?,?,?,?,?,?,?) ", localObject5);
          if ((k > 1) || (MainControl.d))
          {
            localObject4 = localObject3[11].split("\\$\\$", 0);
            localObject5 = localObject3[12].split("\\$\\$", 0);
            localObject6 = localObject3[13].split("\\$\\$", 0);
            localObject3 = localObject3[14].split("\\$\\$", 0);
            MainControl.a("Test", "but_dis_ch_list," + localObject4.length);
            MainControl.a("Test", "but_dis_en_list," + localObject5.length);
            MainControl.a("Test", "but_code_list," + localObject6.length);
            MainControl.a("Test", "but_note_list," + localObject3.length);
            k = localObject3.length;
            j = 1;
            if (j <= k)
              break label2622;
          }
        }
        localObject2 = this.a;
        ((MainControl)localObject2).bl += 1;
      }
      try
      {
        while (true)
        {
          while (true)
          {
            while (true)
            {
              while (true)
              {
                while (true)
                {
                  do
                    Thread.sleep(100L);
                  while ((this.a.bl == this.a.bk) || ((this.a.bl == 30) && (!(MainControl.d)) && (this.a.bj != 19)) || (this.a.H));
                  i += 1;
                }
                this.a.an.add(new BasicNameValuePair("action_value", "get"));
              }
              label2557: MainControl.i(this.a).execSQL("delete from control_list where device_ID= ?", new String[] { localObject4 });
              MainControl.i(this.a).execSQL("delete from button_data where define_ID=? ", new String[] { localObject2 });
            }
            label2604: MainControl.i(this.a).execSQL("insert into control_list (ID,define_ID,control_type,name_ch,brand_ch,control_model,control_version,come_from,device_ID,note,update_time,brand_en,name_en) values (?,?,?,?,?,?,?,?,?,?,?,?,?) ", localObject5);
          }
          label2622: localObject7 = new Object[8];
          localObject7[1] = Integer.valueOf(j);
          localObject7[2] = localObject2;
          localObject7[3] = MainControl.b(localObject4[(j - 1)]);
          localObject7[4] = MainControl.b(localObject5[(j - 1)]);
          localObject7[5] = MainControl.b(localObject6[(j - 1)]);
          localObject7[6] = MainControl.b(localObject3[(j - 1)]);
          localObject7[7] = Integer.valueOf(0);
          if (!(MainControl.d))
            break;
          MainControl.f(this.a).execSQL("insert into button_data (ID,order_ID,define_ID,dis_ch,dis_en,code_str,note,control_ID) values (?,?,?,?,?,?,?,?) ", localObject7);
          j += 1;
        }
        label2761: MainControl.i(this.a).execSQL("insert into button_data (ID,order_ID,define_ID,dis_ch,dis_en,code_str,note,control_ID) values (?,?,?,?,?,?,?,?) ", localObject7);
      }
      catch (InterruptedException localInterruptedException2)
      {
        while (true)
        {
          while (true)
            localInterruptedException2.printStackTrace();
          MainControl.a("Test", "restore," + String.valueOf(this.a.bl) + ",save_id_list:" + this.a.bn[i]);
          MainControl.a("Test", "restore," + String.valueOf(this.a.bl) + ",retrun_str:" + this.a.bc);
        }
      }
    }
  }
}